package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.DzLunboMapper;
import com.ruoyi.system.domain.DzLunbo;
import com.ruoyi.system.service.IDzLunboService;


import com.ruoyi.common.core.domain.entity.SysRole;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.system.service.ISysRoleService;
import com.ruoyi.system.mapper.DzHuiyuanMapper;
import com.ruoyi.system.domain.DzHuiyuan;
import com.ruoyi.system.service.IDzHuiyuanService;

/**
 * 轮播图Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-09-27
 */
@Service
public class DzLunboServiceImpl implements IDzLunboService 
{
    @Autowired
    private DzLunboMapper dzLunboMapper;

    @Autowired
    private ISysRoleService sysRoleService;

    @Autowired
    private IDzHuiyuanService dzHuiyuanService;

    /**
     * 查询轮播图
     * 
     * @param lbId 轮播图主键
     * @return 轮播图
     */
    @Override
    public DzLunbo selectDzLunboByLbId(Long lbId)
    {
        return dzLunboMapper.selectDzLunboByLbId(lbId);
    }

    /**
     * 查询轮播图列表
     * 
     * @param dzLunbo 轮播图
     * @return 轮播图
     */
    @Override
    public List<DzLunbo> selectDzLunboList(DzLunbo dzLunbo)
    {

        //权限控制
        SysUser user=  SecurityUtils.getLoginUser().getUser();
        List<SysRole> listRole= sysRoleService.selectRolesByUserId(user.getUserId());
        int datascope = 5;
        for(SysRole role:listRole){
            if( role.getDataScope()!=null&&Integer.parseInt(role.getDataScope())<datascope){
                datascope=Integer.parseInt(role.getDataScope());
            }
        }
        dzLunbo.setDatascope(datascope);
        if(datascope==4){
            dzLunbo.setCheckDeptId(user.getDeptId());
        }
        if(datascope==5){
            DzHuiyuan huiyuan =  dzHuiyuanService.selectDzHuiyuanByDn(user.getPhonenumber());
            if(huiyuan!=null){
                dzLunbo.setCheckHuiyuanId(huiyuan.getId());
            }else{
                dzLunbo.setCheckHuiyuanId(0l);
            }

        }
        return dzLunboMapper.selectDzLunboList(dzLunbo);
    }

    @Override
    public List<DzLunbo> selectDzLunboListWeb(DzLunbo dzLunbo)
    {
        return dzLunboMapper.selectDzLunboList(dzLunbo);
    }

    /**
     * 新增轮播图
     * 
     * @param dzLunbo 轮播图
     * @return 结果
     */
    @Override
    public int insertDzLunbo(DzLunbo dzLunbo)
    {
        return dzLunboMapper.insertDzLunbo(dzLunbo);
    }

    /**
     * 修改轮播图
     * 
     * @param dzLunbo 轮播图
     * @return 结果
     */
    @Override
    public int updateDzLunbo(DzLunbo dzLunbo)
    {
        return dzLunboMapper.updateDzLunbo(dzLunbo);
    }

    /**
     * 批量删除轮播图
     * 
     * @param lbIds 需要删除的轮播图主键
     * @return 结果
     */
    @Override
    public int deleteDzLunboByLbIds(Long[] lbIds)
    {
        return dzLunboMapper.deleteDzLunboByLbIds(lbIds);
    }

    /**
     * 删除轮播图信息
     * 
     * @param lbId 轮播图主键
     * @return 结果
     */
    @Override
    public int deleteDzLunboByLbId(Long lbId)
    {
        return dzLunboMapper.deleteDzLunboByLbId(lbId);
    }
}
